package com.wanxi.servlet;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.CuisineDTO;
import com.wanxi.service.CuisineService;
import com.wanxi.service.impl.CuisineServiceImpl;
import com.wanxi.util.Tool;
import com.wanxi.vo.CuisineVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

@WebServlet("/cuisine/findAll")
public class CuisineFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        1.乱码
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        2.得到前端的值
        String isShow = req.getParameter("isShow");
//        3.封装到VO
        CuisineVO cuisineVO = new CuisineVO();
        cuisineVO.setIsShow(Tool.strToInt(isShow));
//        4.调用service
        CuisineService cuisineService = new CuisineServiceImpl();
//        5.得到返回值
        List<CuisineDTO> cuisineDTOList = cuisineService.findAll(cuisineVO);
//        6.返回给前端
        resp.getWriter().println(JSONObject.toJSONString(cuisineDTOList));

    }
}
